<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class popularServices extends CWidget {

	public $category = false;

	public function run() {

		if ($this->category) {
			$query = "SELECT \"pageUrl\", \"pageTitle\", \"pageImages\" FROM {{pages}} WHERE \"pageUrl\" LIKE '%" . $this->category . "%' AND \"pageType\" = 'service' AND \"pageActive\" = 1 ORDER BY \"pageSort\" DESC";
		} else {
			$query = "SELECT \"pageUrl\", \"pageTitle\", \"pageImages\" FROM {{pages}} WHERE \"pageType\" = 'service' AND \"pageActive\" = 1 ORDER BY \"pageSort\" DESC";
		}
                $services = Yii::app()->db->getCommandBuilder()->createSqlCommand($query)->queryAll();
		if (!empty($services))
			$this->render('popularservices', array('services' => Yii::app()->db->createCommand($query)->queryAll(TRUE)));
	}

}
